//打印处方,用户信息、目标表格，选择处方,诊断
function print_chufang(user, target_table, contrast, diagnosis) {
    if(!user) {
        layer.msg('请选择一个患者');return false;
    }
    var number = contrast.number;
    var number_id = number.id; //获取处方编号
    var number_time = timetrans(number.created_at); //处方时间
    var table_tr = target_table.find('.number[data-number="'+ number_id +'"]').parent().parent();
    if(table_tr.length <=0) {
        layer.msg('没有可打印的处方');return false;
    }
    var doctor_name = '';
    var total_price = 0.00;
    var chufang_header = [];
    var chufang_bottom = [];
    var content = [];
    chufang_header.push('<style>\
    .chufang_print{ position:relative; padding:20px; padding-top: 10px; font-size:12px;}\
    .chufang_print .mt20{ margin-top:20px;}\
    .chufang_print .mb20{ margin-bottom:20px;}\
    .chufang_print .mb10{ margin-bottom:10px;}\
    .chufang_print .h1{ font-size:24px; text-align:center; font-weight:400; padding:0; margin:20px 0;}\
    .chufang_print .h1 span{ font-size:28px; display:block; margin-top:5px;}\
    .chufang_print .biaozhi{ width:100px; height:100px; position:absolute;right:20px; top:10px; text-align:center;}\
    .chufang_print .biaozhi span{ font-size:23px; display:block; text-align:center; border:1px solid #000; line-height:50px;}\
    .chufang_print .biaozhi div{ margin-top:10px;}\
    .chufang_print .line{ border-top:1px solid #000;}\
    .chufang_print .table td{ line-height:22px;}\
    .chufang_print .rp{ font-size:25px; margin-top:10px;}\
    .chufang_print .bottom{}\
    </style>');
    chufang_header.push('<div class="chufang_print"><h1 class="h1">'+ WG.fullname +'<span>处 方 笺</span></h1><div class="biaozhi"><span>普通</span><div>当日有效</div></div>');
    chufang_header.push('<div style="text-align: right;padding-right: 5px; padding-bottom: 5px;">处方编号：'+ number_id +'</div><div class="line"></div>');
    chufang_header.push('<table width="100%" border="0" cellspacing="0" cellpadding="0" class="mt20 mb10 table">');
    chufang_header.push('<tr><td width="33%">姓名：'+ user.Realname +'</td><td width="33%">性别：'+ user.Sex +'</td><td>年龄：'+ user.Age +'</td></tr>');
    chufang_header.push('<tr><td ><span style="text-align:right;">开具日期：'+ number_time +'</span></td><td colspan="2">临床诊断：'+ diagnosis +'</td></tr>');
    chufang_header.push('<tr><td width="50%">电话：'+ user.Mobile +'</td><td colspan="2" >&nbsp;</td></tr></table>');
    chufang_header.push('<div class="line"></div><div class="rp mb20">Rp</div><div style="height: 350px;">');
    LODOP=getLodop();
    LODOP.SET_PRINT_PAGESIZE(0,"148mm","210mm","A5");
    LODOP.SET_PRINT_MODE("POS_BASEON_PAPER",true);
    var forkey = 0;
    $.each(table_tr, function(idx, val){
        //判断是否是药品
        if($(this).find('.project_type[value="drug"]').length > 0){
            forkey++;
            content.push('<table width="100%" border="0" cellspacing="0" cellpadding="0" class="mt20 mb10 table">');
            content.push('<tr><td width="30">'+ forkey +'、</td><td>'+ $(this).find('.content').text() +'</td><td width="8%">'+ $(this).find('.dosage_zl').text()+ $(this).find('.unit').text() +'</td></tr>');
            content.push('<tr><td>&nbsp;</td><td colspan="2">用法：'+ $(this).find('.usage').text() +'</td></tr></table>');
            var unit_price = parseFloat($(this).find('.total_price').val());
            if(unit_price) {
                total_price += unit_price;
            }
            if(forkey%5==0) {  //已有5个
                LODOP.NewPage();
                chufang_bottom.push('</div><div class="bottom"><div class="line"></div><table width="100%" border="0" cellspacing="0" cellpadding="0" class="mt20 mb10 table">');
                chufang_bottom.push('<tr><td width="33%">药品金额：'+ (total_price.toFixed(2)) +'元</td><td width="33%">医师：'+ doctor_name +'</td><td>调配药师/士：</td></tr>');
                chufang_bottom.push('<tr><td>审核药师：</td><td></td><td>核发、发药药师：</td></tr></table></div></div>');
                LODOP.ADD_PRINT_HTM(20,25,'100%', '100%',chufang_header.join('')+content.join('')+chufang_bottom.join(''));
                content = [];
                chufang_bottom = [];
                total_price = 0.00;
            }
        }
    });
    if(content.length > 0 ){
        LODOP.NewPage();
        chufang_bottom.push('</div><div class="bottom"><div class="line"></div><table width="100%" border="0" cellspacing="0" cellpadding="0" class="mt20 mb10 table">');
        chufang_bottom.push('<tr><td width="33%">药品金额：'+ (total_price.toFixed(2)) +'元</td><td width="33%">医师：'+ doctor_name +'</td><td>调配药师/士：</td></tr>');
        chufang_bottom.push('<tr><td>审核药师：</td><td></td><td>核发、发药药师：</td></tr></table></div></div>');
        LODOP.ADD_PRINT_HTM(20,25,'100%', '100%',chufang_header.join('')+content.join('')+chufang_bottom.join(''));
    }
    LODOP.PREVIEW();
}

//打印检查单,用户信息、目标表格，选择处方
function print_inspects(user, target_table, contrast) {
    if(!user) {
        layer.msg('请选择一个患者');return false;
    }
    var number = contrast.number;
    var number_id = number.id; //获取处方编号
    var number_time = timetrans(number.created_at); //处方时间
    var table_tr = target_table.find('.number[data-number="'+ number_id +'"]').parent().parent();
    if(table_tr.length <=0) {
        layer.msg('没有可打印的检查单');return false;
    }
    var chufang_header = [];
    var chufang_bottom = [];
    var content = [];
    chufang_header.push('<style>\
    .chufang_print{padding:20px; padding-top: 10px; font-size:12px;}\
    .chufang_print .h1{ font-size:20px; font-weight:400; padding:0; margin:20px 0;}\
    .chufang_print .line{ border-top:1px solid #000;}\
    .chufang_print .mb5{ margin-bottom: 5px;}\
    .chufang_print .mb10{ margin-bottom: 10px;}\
    .chufang_print .pt10{ padding-top: 10px;}\
    </style>');
    chufang_header.push('<div class="chufang_print"><h1 class="h1">检查申请单</h1><div class="mb5">姓名：'+ user.Realname +'</div><div class="mb5">性别：'+ user.Sex +'</div>');
    chufang_header.push('<div class="line"></div>');
    LODOP=getLodop();
    LODOP.SET_PRINT_MODE("POS_BASEON_PAPER",true);
    var forkey = 0;
    $.each(table_tr, function(idx, val){
        //判断是否是药品
        if($(this).find('.project_type[value="inspects"]').length > 0){
            forkey++;
            content.push('<div class="mb10 pt10">'+ forkey +'、'+ $(this).find('.content').text() + ' *'+ $(this).find('.dosage_zl').text() +'</div>');
            if(forkey%5==0) {  //已有5个
                LODOP.NewPage();
                chufang_bottom.push('<div class="line"></div><div>申请日期：'+ number_time +'</div></div>');
                LODOP.ADD_PRINT_HTM(20,25,'100%', '100%',chufang_header.join('')+content.join('')+chufang_bottom.join(''));
                content = [];
                chufang_bottom = [];
            }
        }
    });
    if(content.length > 0 ){
        LODOP.NewPage();
        chufang_bottom.push('<div class="line mb10"></div><div>申请日期：'+ number_time +'</div></div>');
        LODOP.ADD_PRINT_HTM(20,25,'100%', '100%',chufang_header.join('')+content.join('')+chufang_bottom.join(''));
    }
    LODOP.PREVIEW();
}